package com.frontop.modules.service.impl;

import com.frontop.common.domain.TUserShowInfo;
import com.frontop.common.domain.UserJurisdiction;
import com.frontop.common.util.ResultJsonUtil;
import com.frontop.dubbo.api.auth.Oauth2Api;
import com.frontop.modules.feign.OauthFeign;
import com.frontop.modules.mapper.TUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;

import javax.annotation.Resource;
import java.util.Map;
/**
 * @author YangBoos
 * @title: TUser
 * @projectName fOauth2ApiImpl
 * @description: 实现dubbo接口，提供auth认证服务提供
 */
@org.apache.dubbo.config.annotation.Service
public class Oauth2ApiImpl implements Oauth2Api {
    @Autowired
    OauthFeign oauthFeign;

    @Resource
    private PasswordEncoder passwordEncoder;
    @Autowired
    private TUserMapper tUserMapper;
    @Override
    public ResultJsonUtil<Object> postAccessToken(Map<String, String> map) {
        return oauthFeign.postAccessToken(map);
    }

    @Override
    public String getEncodePassword(String password) {
        String defultPassword = passwordEncoder.encode(password);
        return defultPassword;
    }

    @Override
    public UserJurisdiction getUserJurisdictionByUserName(String userName) {
        return tUserMapper.getUserJurisdictionByUserName(userName);
    }

    @Override
    public TUserShowInfo selectShowUserInfo(String userName) {
        return tUserMapper.selectShowUserInfo(userName);
    }

    @Override
    public boolean upPwd(String userName,String password) {
        String endPassword = passwordEncoder.encode(password);
        int count = tUserMapper.upPwd(userName,endPassword);
        if (count > 0) {
            return true;
        }else {
            return false;
        }
    }


}
